package main;


import main.Game.Board;
import main.Game.Color;

/**
 * 用于控制整个牌组
 * @author svitter
 *
 */
public class Controler_board {
	public int 			init_board_num = 3;		/** 初始牌数量 */

	private int                 blacknum;           /** 黑牌的数量 */
	private int                 whitenum;           /** 白牌的数量 */
	private int                 blackGroup[];       /** 黑牌的剩余 */
	private int                 whiteGroup[];       /** 白牌的剩余 */

	public Controler_board() {
		// 开始的时候自动调用一次
		blackGroup = new int[20];
		whiteGroup = new int[20];
		resetBoard();
	}
	
	private int _getNewBoard(int num, int group[]) {
		if(num == 0) {
			return -1;
		}
		int random = (int) ((Math.random()) * 12);
		int temp = group[num];
		group[num] = group[random];
		group[random] = temp;
		return group[num];
	}
	
	/**
	 * 依据给出的颜色，返回相应的牌
	 * @param color
	 * @return
	 */
    public Board NewBoard(Color color) {
		 if (color == Color.black) {
			 int num = _getNewBoard(blacknum, blackGroup);
			 blacknum--;
			 return new Board(num, color);
		 }
		 else {
			 int num = _getNewBoard(whitenum, whiteGroup);
			 whitenum--;
			 return new Board(num, color);
         }
    }

	/**
	 * 重置牌组
	 * 一切返回初始状态
	 */
	public void resetBoard() {
		this.blacknum = this.whitenum = 12;
		for	(int i = 0; i < 12; i++) {
			this.blackGroup[i] = this.whiteGroup[i] = i; 
		}
	}
}
